﻿using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using Business;

public partial class Controls_BackEnd_Menu : UserControl
{
    public string Gererate()
    {
        int id;
        int.TryParse(Request["target"], out id);
        if (id == 0) return string.Empty;
        var functions = (List<Functions>)Session[SessionManager.SessionFunctions];
        var menus = functions.FindAll(f => f.FatherID == id);
        menus.Sort((f1, f2) => f1.Order.CompareTo(f2.Order));
        var tab = functions.Find(f => f.FunctionID == id);
        var html = "<h3>" + tab.Name.ToUpper() + "</h3> <ul class=\"nav\">";
        html = menus.Aggregate(html, (current, menu) => current + (" <li><a onclick=\"Loading(100, 100, '');\" href=\"" + Config.ApplicationUrl + id + "/" + menu.FunctionID + "/admin.html\">" + menu.Name + "</a></li>"));
        return string.Format("{0}</ul>", html);
    }
}
